package cn.lh.controller;


import cn.lh.config.Resp;
import cn.lh.entity.req.OrderListReq;
import cn.lh.entity.req.OrderReq;
import cn.lh.entity.req.UserReq;
import cn.lh.entity.vo.OrderVo;
import cn.lh.service.OrderService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author linhong
 * @since 2025-04-14
 */
@Api(tags = "订单")
@Validated
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController{

    @Resource
    private OrderService orderService;

    @ApiOperation(value = "新增/修改订单", notes = "新增/修改订单")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @PostMapping("/createOrUpdate")
    public Resp<?> createOrUpdate(@RequestHeader String authorization, @RequestBody @Valid OrderReq req){
        orderService.saveOrUpdate(req);
        return ok();
    }

    @ApiOperation(value = "删除订单", notes = "删除订单")
    @ApiImplicitParam(name = "orderId", value = "订单id", required = true, paramType = "query", dataType = "Integer")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @DeleteMapping("/delete")
    public Resp<?> updateUser(@RequestHeader String authorization,@RequestParam(value = "orderId") Integer orderId){
        orderService.delete(orderId);
        return ok();
    }
    @ApiOperation(value = "获取订单列表", notes = "获取订单列表")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @GetMapping("/getList")
    public Resp<PageInfo<OrderVo>> getList(@RequestHeader String authorization, OrderListReq req){
        return ok(orderService.getList(req));
    }


}

